# -*- coding: utf-8 -*-
# @Time    : 2020/12/20 下午5:11
# @Author  : lilong


"""
参考链接：https://blog.csdn.net/foneone/article/details/103881687
"""

import torch
import torch.nn as nn

x = torch.LongTensor([[1, 2, 4], [4, 3, 2]])
embeddings = nn.Embedding(5, 5, padding_idx=4)  # 5个词,每个词也是5维
print(embeddings(x))
print(embeddings(x).size())


"""
output:
tensor([[[0.8839, -1.2889, 0.0697, -0.9998, -0.7471],
         [-0.5681, 0.8486, 0.8176, 0.8349, 0.1719],
         [0.0000, 0.0000, 0.0000, 0.0000, 0.0000]],  ->index = 4 赋值 0

[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000],   ->index = 4 赋值 0
[1.4224, 0.2333, 1.9383, -0.7320, 0.9987],
[-0.5681, 0.8486, 0.8176, 0.8349, 0.1719]]],
grad_fn = < EmbeddingBackward >)
torch.Size([2, 3, 5])
"""
